package com.example.springboot.service;


import com.example.springboot.entity.jobs;
import com.example.springboot.mapper.JobsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JobsService {

    @Autowired
    private JobsMapper jobsMapper;

    public List<jobs> findAllJobs() {
        return jobsMapper.findAll();
    }

    public jobs findJobById(int id) {
        return jobsMapper.findById(id);
    }

    public void saveJob(jobs job) {
        if (job.getJob_id() == 0) {
            jobsMapper.insert(job);
        } else {
            jobsMapper.update(job);
        }
    }

    public void deleteJob(int id) {
        jobsMapper.delete(id);
    }

    public List<jobs> getAllJobs() {
        return jobsMapper.getAllJobs();
    }

    public jobs getJobById(Integer id) {
        return jobsMapper.getJobById(id);
    }

    public jobs addJob(jobs job) {
        jobsMapper.addJob(job);
        return job;
    }

    public jobs updateJob(Integer id, jobs job) {
        job.setJob_id(id);
        jobsMapper.updateJob(job);
        return job;
    }

    public void deleteJob(Integer id) {
        jobsMapper.deleteJob(id);
    }

}